<template>
  <div class="doctor-dashboard">
    <!-- 顶部导航栏 -->
    <el-header class="header">
      <div class="header-left">
        <span class="system-title">就诊管理系统</span>
      </div>
      <div class="header-right">
        <span class="welcome-msg">欢迎，{{ user.userInfo.real_name }}</span>
        <el-button type="danger" @click="handleLogout" class="logout-btn">退出登录</el-button>
      </div>
    </el-header>

    <!-- 主体布局：左侧菜单（静态+动态） + 右侧内容 -->
    <el-row style="height: calc(100vh - 60px);">
      <!-- 左侧菜单区（占4列） -->
      <el-col :span="4" class="sidebar-col">
        <div class="menu-section">
          <el-menu
              :default-active="$route.path"
              class="el-menu-vertical-demo"
              background-color="#1e293b"
              text-color="#e2e8f0"
              active-text-color="#fff"
              router
          >
            <el-menu-item
                v-for="menu in listMenu"
                :key="menu.id"
                :index="menu.url"
            >
              {{ menu.name }}
            </el-menu-item>
          </el-menu>
        </div>
      </el-col>

      <!-- 右侧内容区（占20列） -->
      <el-col :span="20" class="content-col">
        <el-main class="main-content">
          <router-view></router-view>
        </el-main>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue';
import { useRouter } from 'vue-router';
import { Setting, Notification } from '@element-plus/icons-vue';
import {UserStore} from '../store/pcUser.js'

const { proxy } = getCurrentInstance();
const router = useRouter();





const user=UserStore();
// 动态菜单数据（从接口获取）
const listMenu = ref([]);
const doctorName = user.userInfo.real_name // 可动态绑定用户姓名
// 加载动态菜单（保留原有逻辑）
onMounted(() => {
  proxy.$axios.get("/pcUser/getMenuList", {
    params: { pc_user_id: user.userInfo.pc_user_id }
  }).then((serverData) => {
    if (serverData.data.code == 0) {
      listMenu.value = serverData.data.data;
      console.log("动态菜单数据（用于对比）：", listMenu.value);

      // 提取动态菜单URL（保留原有逻辑）
      const menuURLArray = [];
      listMenu.value.forEach(menu => {
        menuURLArray.push(menu.url);
      });

      console.log("动态菜单URL列表：", menuURLArray);
      user.userInfo.urlList = menuURLArray;
    }
  });
});

// 退出登录
const handleLogout = () => {
  router.push('/login');
};
</script>

<style scoped>
.doctor-dashboard {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f1f5f9;
}

/* 顶部导航 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 60px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.header-left { display: flex; align-items: center; }
.system-title { font-size: 18px; font-weight: 600; color: #1e293b; }
.header-right { display: flex; align-items: center; gap: 15px; }
.welcome-msg { color: #64748b; }
.logout-btn { margin-left: 10px; }
.header-btn { color: #64748b; transition: color 0.3s; }
.header-btn:hover { color: #1e293b; }

/* 左侧菜单列 */
.sidebar-col {
  padding: 15px;
  height: 100%;
  overflow-y: auto;
  background-color: #0f172a;
}

/* 菜单分区样式（区分静态和动态菜单） */
.menu-section { margin-bottom: 20px; }
.menu-title {
  color: #fff;
  font-size: 14px;
  margin-bottom: 10px;
  padding-left: 10px;
}
.menu-divider {
  border-color: rgba(255, 255, 255, 0.1);
  margin: 10px 0;
}

/* 右侧内容列 */
.content-col {
  height: 100%;
  overflow-y: auto;
}
.main-content {
  padding: 20px;
  height: 100%;
  background-color: #f1f5f9;
}

/* 菜单样式优化 */
.el-menu-vertical-demo {
  border-right: none;
  margin-bottom: 10px;
}
</style>